package test;

import common.Utils;
import org.openqa.selenium.By;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;

import java.time.Duration;

public class MyPost extends Utils {
    public static String url = "http://127.0.0.1:9580/index.html";

    public MyPost() {
        super(url);
    }

    //点赞
    public void thumbsUp() throws InterruptedException {
        LoginPage loginPage = new LoginPage();
        loginPage.login();
        driver.findElement(By.cssSelector("#index_nav_avatar")).click();
        driver.findElement(By.cssSelector("#index_user_profile")).click();
        driver.findElement(By.cssSelector("#profile_article_body > li:nth-child(1) > div.card.timeline-event-card > div > div > div > div > div.text-truncate > a > strong")).click();
        driver.findElement(By.cssSelector("#details_btn_like_count")).click();
        Thread.sleep(4000);
    }

    //编辑
    public void edit() throws InterruptedException {
        driver.findElement(By.cssSelector("#details_artile_edit")).click();
        driver.findElement(By.cssSelector("#edit_article_title")).clear();
        driver.findElement(By.cssSelector("#edit_article_title")).sendKeys("第一篇帖子(修改版)");
        WebDriverWait wait = new WebDriverWait(driver, Duration.ofSeconds(10));
        wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector("#edit_article_submit")));
        driver.findElement(By.cssSelector("#edit_article_submit"));
    }

    //删除
    public void delete(){
        driver.findElement(By.cssSelector("#index_nav_avatar")).click();
        driver.findElement(By.cssSelector("#index_user_profile")).click();
        driver.findElement(By.cssSelector("#profile_article_body > li:nth-child(1) > div.card.timeline-event-card > div > div > div > div > div.text-truncate > a > strong")).click();
        driver.findElement(By.cssSelector("#bit-forum-content > div.page-body > div > div > div:nth-child(1) > div.col-9.card.card-lg > div.card-footer.bg-transparent.mt-auto.justify-content-end > div > div:nth-child(3) > div > a")).click();
        driver.findElement(By.cssSelector("#details_artile_delete")).click();
    }

}
